import { getOrder } from "api/orderApi";

const LoadOrder = {
    data: () => ({
        id: null,
        order: {},
        items: [],
        sku: {},
        product: {},
        amount: 0
    }),
    methods: {
        async loadOrder() {
            const response = await getOrder(this.id, { include: 'items.sku.product' })
            this.order = response
            this.items = response.items
            this.sku = this.items[0].sku
            this.product = this.sku.product
            this.amount = this.items[0].amount
        }
    },
    async onLoad(options) {
        this.id = options.id
        await this.loadOrder()
    }
}

export default LoadOrder
